package top.goldenyear.porpoise.system.setting.controller.admin;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.setting.dto.ConfigSearchReq;
import top.goldenyear.porpoise.system.setting.model.Config;
import top.goldenyear.porpoise.system.setting.service.ConfigService;

/**
 * 参数配置表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-15
 */
@Component(tag = "adminApi")
@Mapping("/setting/config")
@Slf4j
public class ConfigAdminController extends BaseController {
  @Inject private ConfigService service;

  @Post
  @Mapping("create")
  public Ret create(@Body Config config) {
    return Ret.okWithData(service.createConfig(config));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body Config config) {
    return Ret.okWithData(service.updateConfig(config));
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Integer id) {
    return Ret.okWithData(service.getConfig(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Integer id) {
    return Ret.okWithData(service.deleteConfig(id));
  }

  @Post
  @Delete
  @Mapping("batchDel")
  public Ret batchDel(@Body List<Integer> ids) {
    return Ret.okWithData(service.batchDelConfig(ids));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage, ConfigSearchReq searchReq) {
    return Ret.okWithData(service.paginateConfig(qPage, searchReq));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    Config config = getBean(Config.class);
    return Ret.okWithData(service.listConfig(config));
  }

  @Get
  @Mapping("options")
  public Ret options() {
    Config config = getBean(Config.class);
    return Ret.okWithData(service.listConfig(config));
  }
}
